From: master@cats.UCSC.EDU (Mark Wedel)
Date: Tue, 1 Jun 1993 22:10:25 GMT
Newsgroups: comp.sources.x
Subject: v20i006:  xblockbuster - a variation of the break-out type games, Patch03

Submitted-by: master@cats.UCSC.EDU (Mark Wedel)
Posting-number: Volume 20, Issue 6
Archive-name: xblockbuster/patch03
Environment: X11
Patch-To: xblockbuster: Volume 19, Issue 44-49,79



This is patch #3 for xblockbuster.  The changes are minor:
Changes from v1.02 to v1.03

  file locking implemented for the scorefile.  By Gerald Vogt <vogt@isa.de>
  this adds the files lock.c and lock.h

  added S_ISDIR macro to xblockbuster.c for Mips machines

 This is a shell archive.  It contains 3 files, the patch file
(xbb.patch3) and two new files - lock.c and lock.h.  Unpack
this file in the xblockbuster directory. 

 A completely patched version of XBlockBuster 1.03 should either be
on or appear in the near future on export.lcs.mit.edu.  The
compressed file is about 82k.

 Mark Wedel
master@cats.ucsc.edu


#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  xbb.patch3 lock.c lock.h
# Wrapped by master@sleipner on Wed May 19 22:59:24 1993
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'xbb.patch3' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'xbb.patch3'\"
else
echo shar: Extracting \"'xbb.patch3'\" \(7648 characters\)
sed "s/^X//" >'xbb.patch3' <<'END_OF_FILE'
Xdiff -c xblockbuster1.02/CHANGES xblockbuster1.03/CHANGES
X*** xblockbuster1.02/CHANGES	Fri Apr  2 20:44:44 1993
X--- xblockbuster1.03/CHANGES	Sat Apr 17 23:07:02 1993
X***************
X*** 1,3 ****
X--- 1,10 ----
X+ Changes from v1.02 to v1.03
X+ 
X+   file locking implemented for the scorefile.  By Gerald Vogt <vogt@isa.de>
X+   this adds the files lock.c and lock.h
X+ 
X+   added S_ISDIR macro to xblockbuster.c for Mips machines
X+ 
X  Changes from v1.01 to v1.02
X  
X    rand and srand are now used as defaults on HP machines.
Xdiff -c xblockbuster1.02/Imakefile xblockbuster1.03/Imakefile
X*** xblockbuster1.02/Imakefile	Fri Apr  2 23:13:07 1993
X--- xblockbuster1.03/Imakefile	Sat Apr 17 20:21:14 1993
X***************
X*** 17,22 ****
X--- 17,23 ----
X  #ifndef StageDir
X  #define StageDir $(LIBDIR)/xblockbuster
X  #endif
X+ CFLAGS += -Wall
X  
X  STAGEDIR = StageDir
X  
X***************
X*** 25,34 ****
X          DEFINES = -DSTAGEDIR=\"$(STAGEDIR)\"
X          DEPLIBS = $(DEPXLIB)
X  LOCAL_LIBRARIES = $(XLIB)
X!           SRCS1 = balls_pallet.c bricks.c deflection.c save.c score.c stage.c \
X!                   xblockbuster.c
X!           OBJS1 = balls_pallet.o bricks.o deflection.o save.o score.o stage.o \
X!                   xblockbuster.o
X            SRCS2 = stagemm.c
X            OBJS2 = stagemm.o
X         PROGRAMS = xblockbuster stagemm
X--- 26,35 ----
X          DEFINES = -DSTAGEDIR=\"$(STAGEDIR)\"
X          DEPLIBS = $(DEPXLIB)
X  LOCAL_LIBRARIES = $(XLIB)
X!           SRCS1 = balls_pallet.c bricks.c deflection.c lock.c save.c score.c \
X!                   stage.c xblockbuster.c
X!           OBJS1 = balls_pallet.o bricks.o deflection.o lock.o save.o score.o \
X!                   stage.o xblockbuster.o
X            SRCS2 = stagemm.c
X            OBJS2 = stagemm.o
X         PROGRAMS = xblockbuster stagemm
XOnly in xblockbuster1.03: Makefile
Xdiff -c xblockbuster1.02/Makefile.noIm xblockbuster1.03/Makefile.noIm
X*** xblockbuster1.02/Makefile.noIm	Sat Mar 20 03:11:41 1993
X--- xblockbuster1.03/Makefile.noIm	Sat Apr 17 19:27:01 1993
X***************
X*** 1,10 ****
X  #
X  # Makefile for XBlockbuster
X  #
X! HDRS= xblockbuster.h patchlevel.h
X! SRCS = balls_pallet.c bricks.c deflection.c save.c score.c stage.c \
X  	xblockbuster.c 
X! OBJS = balls_pallet.o bricks.o deflection.o save.o score.o stage.o \
X  	xblockbuster.o 
X  
X  # Where you want the executable installed
X--- 1,10 ----
X  #
X  # Makefile for XBlockbuster
X  #
X! HDRS= xblockbuster.h patchlevel.h lock.h
X! SRCS = balls_pallet.c bricks.c deflection.c lock.c save.c score.c stage.c \
X  	xblockbuster.c 
X! OBJS = balls_pallet.o bricks.o deflection.o lock.o save.o score.o stage.o \
X  	xblockbuster.o 
X  
X  # Where you want the executable installed
Xdiff -c xblockbuster1.02/README xblockbuster1.03/README
X*** xblockbuster1.02/README	Tue Mar 30 20:19:06 1993
X--- xblockbuster1.03/README	Sat Apr 17 19:33:05 1993
X***************
X*** 97,110 ****
X  
X  BUGS/TODO:
X  
X-  I have gotten several reports of the pallette not appearing on the
X- screen, yet the balls are appearing (both use the gc_xor structure, so
X- I don't have any idea what the problem is, and can't reproduce it
X- myself.)  This problem seems to be happening more on BW systems.  My
X- only thought right now is perhaps the window wasn't made the proper size,
X- so the bottom is cut off.  But even then, if the pointer is moved near
X- the top of the window, the side crosshairs should still appear.
X- 
X   A nice opening screen, showing the bricks (with proper coloring, if 
X  applicable), along with descriptions of what each brick does.
X  
X--- 97,102 ----
XCommon subdirectories: xblockbuster1.02/SKELS and xblockbuster1.03/SKELS
XCommon subdirectories: xblockbuster1.02/STAGES and xblockbuster1.03/STAGES
XCommon subdirectories: xblockbuster1.02/STAGES.try and xblockbuster1.03/STAGES.try
XCommon subdirectories: xblockbuster1.02/STAGES.wacko and xblockbuster1.03/STAGES.wacko
XCommon subdirectories: xblockbuster1.02/icons and xblockbuster1.03/icons
XOnly in xblockbuster1.03: lock.c
XOnly in xblockbuster1.03: lock.h
Xdiff -c xblockbuster1.02/patchlevel.h xblockbuster1.03/patchlevel.h
X*** xblockbuster1.02/patchlevel.h	Fri Mar 26 01:21:39 1993
X--- xblockbuster1.03/patchlevel.h	Sat Apr 17 19:39:55 1993
X***************
X*** 1 ****
X! #define VERSION	"XBlockBuster 1.02"
X--- 1 ----
X! #define VERSION	"XBlockBuster 1.03"
Xdiff -c xblockbuster1.02/score.c xblockbuster1.03/score.c
X*** xblockbuster1.02/score.c	Wed Mar 24 18:46:51 1993
X--- xblockbuster1.03/score.c	Sat Apr 17 20:30:49 1993
X***************
X*** 17,22 ****
X--- 17,23 ----
X   */
X  
X  #include "xblockbuster.h"
X+ #include "lock.h"
X  
X  struct Score {
X  	int             score, balls_left;
X***************
X*** 52,61 ****
X--- 53,74 ----
X  
X  	/* read the score file into the array */
X  	sprintf( buf, SCOREFILE, playground );
X+ 
X+ #ifdef LOCK_FILE
X+ 	if (LockScoreFile(buf) == -1)
X+ 	  exit(1);
X+ #endif
X+ 
X  	if ( !( fd = fopen(buf, "r+" ) ) ) {
X  		perror( "No score file" );
X  		exit( 1 );
X  	}
X+ 
X+ #ifdef LOCK_FCNTL
X+ 	if (LockFile(fileno(fd)) == -1)
X+ 	  exit(1);
X+ #endif
X+ 
X  	for ( s = 0; s < NB_SCORES; s++ ) {
X  		fscanf( fd, "%d:%d:%s\n", &score_board[s].score,
X  			&score_board[s].balls_left,
X***************
X*** 109,115 ****
X--- 122,137 ----
X  				 score_board[s].login );
X  		}
X  	}
X+ 
X+ #ifdef LOCK_FCNTL
X+ 	UnlockFile(fileno(fd));
X+ #endif
X+ 
X  	fclose( fd );
X+ 
X+ #ifdef LOCK_FILE
X+ 	UnlockScoreFile(buf);
X+ #endif
X  
X  	/* show score board */
X  	center_text( 0, "Top Scores" );
XOnly in xblockbuster1.02: stagemm.o
Xdiff -c xblockbuster1.02/xblockbuster.c xblockbuster1.03/xblockbuster.c
X*** xblockbuster1.02/xblockbuster.c	Wed Mar 31 19:27:01 1993
X--- xblockbuster1.03/xblockbuster.c	Sat Apr 17 23:06:10 1993
X***************
X*** 30,35 ****
X--- 30,40 ----
X  static char *disp=NULL, *play="default";
X  static int winposx=0, winposy=0,geomask,no_pause=FALSE;
X  
X+ 
X+ #ifdef Mips
X+ #define S_ISDIR(m)      (((m)&S_IFMT) == S_IFDIR)
X+ #endif
X+ 
X  void event_handler()
X  {
X  	XEvent	e;
Xdiff -c xblockbuster1.02/xblockbuster.h xblockbuster1.03/xblockbuster.h
X*** xblockbuster1.02/xblockbuster.h	Tue Mar 30 20:11:59 1993
X--- xblockbuster1.03/xblockbuster.h	Sat Apr 17 20:47:36 1993
X***************
X*** 20,25 ****
X--- 20,36 ----
X   * SYSTEM DEPENDENT OPTIONS
X   */
X  
X+ /* NOTE: only one of LOCK_FCTNL or LOCK_FILE should be defined. */
X+ /* If neither are defined, no file locking will be done */
X+ 
X+ /* Use fcntl to lock the scorefile */
X+ #define LOCK_FCNTL
X+ /* Use a different locking method for the score file.  Maybe try it
X+   if fcntl does not work.  If you do use LOCK_FILE, the STAGES
X+ directories themselves need to be publicly writable, as a lockfile
X+ is written in them */
X+ /*#define LOCK_FILE*/
X+ 
X  /* STAGEDIR should, in general, be defined in the (I)Makefile */
X  #ifndef STAGEDIR
X  #define STAGEDIR	"/usr/games/lib/blockbuster"
Xdiff -c xblockbuster1.02/xblockbuster.man xblockbuster1.03/xblockbuster.man
X*** xblockbuster1.02/xblockbuster.man	Wed Mar 31 19:43:21 1993
X--- xblockbuster1.03/xblockbuster.man	Sat Apr 17 19:33:47 1993
X***************
X*** 283,287 ****
X  the bricks it was unable to color.  If using alternate bricks, it can be
X  difficult to differentiate bricks without the coloring.
X  .LP
X! None of the standard command line X arguements are interperted.  Likewise,
X! none of the standard X defaults (in the .Xdefaults file) are used.
X--- 283,288 ----
X  the bricks it was unable to color.  If using alternate bricks, it can be
X  difficult to differentiate bricks without the coloring.
X  .LP
X! Only a few of the standard command line X arguements are interperted.
X! Likewise,
X! only a few of the standard X defaults (in the .Xdefaults file) are used.
END_OF_FILE
if test 7648 -ne `wc -c <'xbb.patch3'`; then
    echo shar: \"'xbb.patch3'\" unpacked with wrong size!
fi
# end of 'xbb.patch3'
fi
if test -f 'lock.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'lock.c'\"
else
echo shar: Extracting \"'lock.c'\" \(3733 characters\)
sed "s/^X//" >'lock.c' <<'END_OF_FILE'
X/*
X** lock.c: this module provides a simple locking mechanism
X**
X**  	   LockScoreFile(filename) locks the given file. returns -1 on error.
X**         UnlockScoreFile(filename) unlocks the given file.
X**  	   LockFile(fd) locks the given file descriptor using fcntl.
X**  	   UnlockFile(fd) unlocks the given file descriptor.
X**
X** the lockfilename is built from the given parameter by adding ".lock" at
X** the end of it. the callers process id will be written in the file.
X** when the file is unlocked again the pid will be read and checked
X** before the file is unlinked.
X**
X** LockFile and UnlockFile use fcntl on an open file descriptor.
X**
X** Copyright (C) 1993, Gerald Vogt <vogt@isa.de>
X** 
X** This program is free software; you can redistribute it and/or modify
X** it under the terms of the GNU General Public License as published by
X** the Free Software Foundation; either version 1, or (at your option)
X** any later version.
X**
X** This program is distributed in the hope that it will be useful,
X** but WITHOUT ANY WARRANTY; without even the implied warranty of
X** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
X** GNU General Public License for more details.
X**
X*/
X
X#include <stdio.h>
X#include <fcntl.h>
X#include <malloc.h>
X#include "xblockbuster.h"
X#include "lock.h"
X
X#define MAXTRY 30
X
X#ifdef LOCK_FILE
Xchar	*CreateLockFileName(scorefile)
Xchar	*scorefile;
X{
X    char    *buffer;
X
X    buffer = malloc(strlen(scorefile) + 6);
X
X    if (buffer != (char *) NULL) {
X	strcpy(buffer, scorefile);
X	strcat(buffer, ".lock");
X    }
X
X    return(buffer);
X}
X
Xint LockScoreFile(scorefile)
Xchar	*scorefile;
X{
X    char    *filename;
X    int	    ret;
X    char    string[10];
X    int	    tryCount;
X	extern char *sys_errlist[];
X	extern int errno;
X
X    filename = CreateLockFileName(scorefile);
X   
X    if (filename == (char *) NULL)
X      return(-1);
X
X    tryCount = 0;
X
X    do {
X	ret = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0664);
X	tryCount++;
X	
X	if (ret == -1) {
X		fprintf(stderr,"Could not open %s:%s\n",filename,sys_errlist[errno]);
X
X	    if (tryCount == MAXTRY) {
X		fprintf(stderr, "Giving up.\n");
X		free(filename);
X		return(-1);
X	    }
X	    sleep(1);
X	}
X    } while (ret == -1);
X
X    sprintf(string, "%d", getpid());
X    write(ret, string, strlen(string) + 1);
X
X    close(ret);
X    free(filename);
X    return(0);
X}
X      
Xvoid	UnlockScoreFile(scorefile)
Xchar	*scorefile;
X{
X    char    *filename;
X    int	    ret, len;
X    char    string[10];
X	extern int atoi();
X
X    filename = CreateLockFileName(scorefile);
X    
X    if (filename == (char *) NULL)
X      return;
X
X    ret = open(filename, O_RDONLY);
X
X    if (ret == -1) {
X	perror("open score lock file");
X	free(filename);
X	return;
X    }
X
X    len = read(ret, string, 10);
X
X    if (len == -1) {
X	perror("reading score lock file");
X	close(ret);
X	free(filename);
X	return;
X    }
X
X    len = atoi(string);
X
X    close(ret);
X
X    if (len == getpid())
X      unlink(filename);
X    else
X      fprintf(stderr, "Score lock pid does not match\n");
X
X    free(filename);
X}
X#endif
X
X#ifdef LOCK_FCNTL
Xint LockFile(fd)
Xint fd;
X{
X    int	    ret;
X    int	    tryCount;
X    struct flock fl;
X
X    tryCount = 0;
X
X    do {
X	fl.l_type = F_WRLCK;
X	fl.l_whence = 0;
X	fl.l_start = 0L;
X	fl.l_len = 0L;
X	
X	ret = fcntl(fd, F_SETLK, &fl);
X
X	tryCount++;
X	
X	if (ret == -1) {
X	    perror("fcntl");
X
X	    if (tryCount == MAXTRY) {
X		fprintf(stderr, "Giving up.\n");
X		return(-1);
X	    }
X	    sleep(1);
X	}
X    } while (ret == -1);
X
X    return(0);
X}
X      
Xvoid	UnlockFile(fd)
Xint 	fd;
X{
X    int	    ret;
X    struct flock fl;
X
X    fl.l_type = F_UNLCK;
X    fl.l_whence = 0;
X    fl.l_start = 0L;
X    fl.l_len = 0L;
X
X    ret = fcntl(fd, F_SETLK, &fl);
X
X    if (ret == -1) {
X	perror("fcntl");
X    }
X}
X#endif
END_OF_FILE
if test 3733 -ne `wc -c <'lock.c'`; then
    echo shar: \"'lock.c'\" unpacked with wrong size!
fi
# end of 'lock.c'
fi
if test -f 'lock.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'lock.h'\"
else
echo shar: Extracting \"'lock.h'\" \(1164 characters\)
sed "s/^X//" >'lock.h' <<'END_OF_FILE'
X/*
X** lock.h: headerfile for lock.c
X**
X**  	   LockScoreFile(filename) locks the given file. returns -1 on error.
X**         UnlockScoreFile(filename) unlocks the given file.
X**
X** the lockfilename is built from the given parameter by adding ".lock" at
X** the end of it. the callers process id will be written in the file.
X** when the file is unlocked again the pid will be read and checked
X** before the file is unlinked.
X**
X** Copyright (C) 1993, Gerald Vogt <vogt@isa.de>
X** 
X** This program is free software; you can redistribute it and/or modify
X** it under the terms of the GNU General Public License as published by
X** the Free Software Foundation; either version 1, or (at your option)
X** any later version.
X**
X** This program is distributed in the hope that it will be useful,
X** but WITHOUT ANY WARRANTY; without even the implied warranty of
X** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
X** GNU General Public License for more details.
X**
X*/
X
X#ifdef LOCK_FILE
Xextern char *CreateLockFileName();
Xextern int LockScoreFile();
Xextern void UnlockScoreFile();
X#endif
X#ifdef LOCK_FCNTL
Xextern int LockFile();
Xextern void UnlockFile();
X#endif
END_OF_FILE
if test 1164 -ne `wc -c <'lock.h'`; then
    echo shar: \"'lock.h'\" unpacked with wrong size!
fi
# end of 'lock.h'
fi
echo shar: End of shell archive.
exit 0

exit 0 # Just in case...
-- 
  // chris@IMD.Sterling.COM       | Send comp.sources.x submissions to:
\X/  Amiga - The only way to fly! |    sources-x@imd.sterling.com
 "It's intuitively obvious to the |
  most casual observer..."        | GCS d+/-- p+ c++ l+ m+ s++/+ g+ w+ t+ r+ x+

